﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Com.Rivyer.Web.admin
{
    public partial class adduser : System.Web.UI.Page
    {
        Com.Rivyer.BLL.userauthorityBll authoritybll = new BLL.userauthorityBll();
        Com.Rivyer.BLL.userBll userbll = new BLL.userBll();
        Com.Rivyer.BLL.userinfoBll userinfobll = new BLL.userinfoBll();
        
        protected void Page_Load(object sender, EventArgs e)
        {
            //非法操作验证
            if (Session["username"] == null
                || Session["username"].ToString().Trim().Length == 0)
            {
                Response.Write("<script>top.location='../login.aspx'</script>");
            }
        }

        protected void btn_add_Click(object sender, EventArgs e)
        {
            Model.userModel usermodel = new Model.userModel();
            usermodel.username = username.Text.Trim();
            usermodel.userpwd = "111";
            Model.userinfoModel infomodel = new Model.userinfoModel();
            infomodel.username = username.Text.Trim();
            infomodel.realname = realname.Text.Trim();
            Model.userauthorityModel authoritymodel = new Model.userauthorityModel();
            authoritymodel.username = username.Text.Trim();
            if ( !userbll.Exists(username.Text.Trim())
                && userbll.Add(usermodel)
                && userinfobll.Add(infomodel)
                && authoritybll.Add(authoritymodel))
            {
                new BLL.useroperatelogBll().AddLog(Session["username"].ToString(), "增加", string.Format("用户:{0}", usermodel.username));
                Maticsoft.Common.MessageBox.Show(this, "添加成功!初始密码:111");
            }
            else
            {
                Maticsoft.Common.MessageBox.Show(this,"用户名已经存在,不允许重复注册!");
            }
        }
    }
}